// components/eroom/eroom.js
const app = getApp();
var rapi = require('../../_self/api.js');
const sel_item = app.sel_item;
var pm = require('../../_self/premap.js');
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    jxlid: {
      type: String,
      observer: function (newVal, oldVal) {
        if (newVal != oldVal) {
          //更新调用请求函数
          console.log(newVal)
          var _ = this;
          _.setData({
            jxlid:newVal
          })
          _.ReqFree(newVal);
        }
      }
    }
  },
  /**
   * 组件生命周期
   */
  lifetimes: {

  },
  /**
   * 组件的初始数据
   */
  data: {
    CustomBar: app.globalData.CustomBar,
    TabCur: 0,
    scrollLeft: 0,
    timepart: [
      "上午", "下午", "晚上", "全天"
    ],
    timeids: [
      "am", "pm", "night", "allday"
    ],
    index: 0,
    freelist:[],
    jxlid:null

  },
  /**
   * 组件生命周期
   */
  lifetimes: {
    created() {

    }
  },
  /**
   * 组件的方法列表
   */
  methods: {

    tabSelect(e) {
      this.setData({
        TabCur: e.currentTarget.dataset.id,
        scrollLeft: (e.currentTarget.dataset.id - 1) * 60
      },()=>{
        console.log('请求')
        this.ReqFree(this.data.jxlid)
      })
    },
    ReqFree(jxlid) {
      wx.showLoading();
      //请求空闲教室
      var _ = this;
      rapi.getKxJscx(sel_item, _.data.timeids[_.data.TabCur], jxlid).then(res => {
       // console.log(res)
        if (res.result.length != 0) {
          var tfree = pm.PreFreeRoom(res.result[0].jsList)
          console.log(tfree)
          _.setData({
            freelist:tfree
          })
          wx.hideLoading();
        }else{
          //无数据
          console.log('未获取到数据')
          wx.hideLoading();
        }
      })

    }
  }
})